package com.petshop.controller;

import com.petshop.pojo.Products;
import com.petshop.service.ProductsService;
import com.petshop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("products")
@CrossOrigin
public class ProductsController {
    @Autowired
    private ProductsService productsService;

    /*
    增加一个商品信息
     */
    @PostMapping("insertProduct")
    public Result insertProduct(@RequestBody Products products) {
        Result result = productsService.insertProduct(products);
        return result;
    }

    /*
    下架商品
     */
    @GetMapping("outProduct")
    public Result outProduct(@RequestParam Integer productId) {
        Result result = productsService.outProduct(productId);
        return result;
    }

    /*
    批量下架商品
     */
    @PostMapping("outBatchProduct")
    public Result outBatchProduct(@RequestBody ArrayList<Integer> idList) {
        Result result = productsService.outBatchProduct(idList);
        return result;
    }

    /*
    修改商品信息
     */
    @PostMapping("updateProduct")
    public Result updateProduct(@RequestBody Products products) {
        Result result = productsService.updateProduct(products);
        return result;
    }

    /*
    查询所有非宠物类商品列表
     */
    @GetMapping("queryProduct")
    public Result queryProduct(String name, String category, Integer pageCount, Integer productPerPage) {
        Result result = productsService.queryProduct(name, category, pageCount, productPerPage);
        return result;
    }

    /*
    仅仅查询第一页商品
     */
    @GetMapping("queryFirstProduct")
    public Result queryFirstProduct(String name, String category, Integer pageCount, Integer productPerPage) {
        Result result = productsService.queryFirstProduct(name, category, pageCount, productPerPage);
        return result;
    }

    /*
    根据商品id查询商品信息
     */
    @GetMapping("queryProductById")
    public Result queryProductById(Integer productId) {
        Result result = productsService.queryProductById(productId);
        return result;
    }
}
